//
//  ljjiftButton.ljjift
//  AiTouYun
//
//  Created by liujunjie on 2018/9/15.
//  Copyright © 2018年 junjie.liu. All rights reserved.
//

import UIKit

public extension UIButton {

    /*
     标题
     自选状态
     默认
     选中
     */
     @discardableResult
    public func ljj_title_state(_ title: String, _ state: UIControl.State) -> UIButton {
        self.setTitle(title, for: state)
        return self
    }
    
     @discardableResult
    public func ljj_title_selected(_ title: String) -> UIButton {
        self.setTitle(title, for: .selected)
        return self
    }
    
     @discardableResult
    public func ljj_title_normal(_ title: String) -> UIButton {
        self.setTitle(title, for: .normal)
        return self
    }
    
    /*
     标题颜色
     自选状态
     默认
     选中
     */
     @discardableResult
    public func ljj_titleColor_state(_ color : UIColor, _ state: UIControl.State) -> UIButton {
        self.setTitleColor(color, for: state)
        return self
    }
    
     @discardableResult
    public func ljj_titleColor_normal(_ color : UIColor) -> UIButton {
        self.setTitleColor(color, for: .normal)
        return self
    }
    
     @discardableResult
    public func ljj_titleColor_selected(_ color : UIColor) -> UIButton {
        self.setTitleColor(color, for: .selected)
        return self
    }
    
    
    /*
     图片
     自选状态
     默认
     选中
     */
    public func ljj_image_state(_ filePath: String, _ state : UIControl.State) -> UIButton {
        self.setImage(UIImage(named: filePath), for: state)
        return self
    }
    
     @discardableResult
    public func ljj_image_normale(_ filePath: String) -> UIButton {
        self.setImage(UIImage(named: filePath), for: .normal)
        return self
    }
    
     @discardableResult
    public func ljj_image_selected(_ filePath: String) -> UIButton {
        self.setImage(UIImage(named: filePath), for: .selected)
        return self
    }
    
    /*
     背景色
     默认
     */
     @discardableResult
    public func ljj_backgroundColor(_ color: UIColor) -> UIButton {
        self.backgroundColor = color
        return self
    }
    
     @discardableResult
    public func ljj_backgroundColor_normale_selected(_ normaleColor: UIColor, _ selectedColor: UIColor) -> UIButton {
        if self.isSelected == true {
            self.backgroundColor = selectedColor
        }else{
            self.backgroundColor = normaleColor
        }
        return self
    }
    
    /*
     字体
     大小
     设置字体格式
     */
     @discardableResult
    public func ljj_fontSize(_ font: CGFloat) -> UIButton {
        self.titleLabel?.font = UIFont.systemFont(ofSize: font)
        return self
    }
    
     @discardableResult
    public func ljj_fontName(_ fontName: String, _ fontSize: CGFloat) -> UIButton {
        self.titleLabel?.font = UIFont(name: fontName, size: fontSize)
        return self
    }
    
    /*
     对齐方式
     */
     @discardableResult
    public func ljj_alignment(_ aligment: UIControl.ContentHorizontalAlignment) -> UIButton {
        self.contentHorizontalAlignment = aligment
        return self
    }
    
    /*
     readius
     */
     @discardableResult
    public func ljj_cornerRadius(_ radius: CGFloat) -> UIButton {
        self.layer.cornerRadius = radius
        self.layer.masksToBounds = true
        return self
    }
    
    /*
     borderWidth
     */
     @discardableResult
    public func ljj_borderWidth(_ color: UIColor, border: CGFloat) -> UIButton {
        self.layer.borderColor = color.cgColor
        self.layer.borderWidth = border
        return self
    }
    
    /*
     hiden
     */
     @discardableResult
    public func ljj_hidden(_ hidden: Bool) -> UIButton {
        self.isHidden = hidden
        return self
    }
    
    /*响应事件*/
     @discardableResult
    public func ljj_targetAction(_ target: AnyObject, action: Selector) -> UIButton {
        self.addTarget(target, action: action, for: .touchUpInside)
        return self
    }
    
    public func ljj_copyButton(button: inout UIButton) {
        button = self 
    }
}
